const initialState = {
  plan: {},
  fixed_products: [],
  remv_arch_products: [],
  rolePerms: [],
  logged: false,
};

export const UserType = {
  technician: 'technician', // 技师
  provider: 'provider', // 供应商
  dentist: 'dentist', // 医生
  clinic: 'clinic', // 诊所
};

export const UserActions = {
  USER_UPDATE: 'user_update',
  USER_SIGN_IN: 'user_sign_in',
  USER_SIGN_OUT: 'user_sign_out',
};

export const UserState = {
  EXPIRED: 'expired',
};

export function updateUser(payload) {
  return {
    type: UserActions.USER_UPDATE,
    payload,
  };
}

export function userSingIn() {
  return {
    type: UserActions.USER_SIGN_IN,
  };
}

export function userSignOut() {
  return {
    type: UserActions.USER_SIGN_OUT,
  };
}

export default function user(state = initialState, action) {
  switch (action.type) {
    case UserActions.USER_UPDATE:
      return {...state, ...action.payload};
    case UserActions.USER_SIGN_IN:
      return {...state, logged: true};
    case UserActions.USER_SIGN_OUT:
      return {
        plan: {},
        fixed_products: [],
        remv_arch_products: [],
        rolePerms: [],
      };
    default:
      return state;
  }
}
